package net.learn.system.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.utils.Result;
import net.learn.system.query.SysRadioQuery;
import net.learn.system.service.SysRadioService;
import net.learn.system.vo.SysRadioVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

/**
 * 单选管理
 */
@RestController
@RequestMapping("sys/radio")
@Tag(name="单选管理")
@AllArgsConstructor
public class SysRadioController {
    @Autowired
    SysRadioService radioService;

    @GetMapping("getRadio")
    @Operation(summary = "分页")
    public Result<PageResult<SysRadioVO>> getRadio(@Valid SysRadioQuery query){
        PageResult<SysRadioVO> page = radioService.qryRadioListPage(query);
        return Result.ok(page);
    }
    @PostMapping("getRadioList")
    @Operation(summary = "列表")
    public Result<List<SysRadioVO>> list(@RequestBody @Valid SysRadioQuery query){
        List<SysRadioVO> list = radioService.qryRadioList();

        return Result.ok(list);
    }
    @PostMapping("getRadioPaper")
    @Operation(summary = "获取试卷单选列表")
    public Result<List<SysRadioVO>> getRadioPaper(@RequestBody @Valid SysRadioQuery query){
        List<SysRadioVO> list = radioService.qryRadioPaper(query);

        return Result.ok(list);
    }

    @PostMapping("getRadioPaperList")
    @Operation(summary = "获取试卷正在考试的单选列表")
    public Result<List<SysRadioVO>> getRadioPaperList(@RequestBody @Valid SysRadioQuery query){
        List<SysRadioVO> list = radioService.qryRadioPaperList(query);

        return Result.ok(list);
    }

    @PostMapping("getRadioRandList")
    @Operation(summary = "获取随机单选题")
    public Result<List<SysRadioVO>> getRadioRandList(@RequestBody @Valid SysRadioQuery query){
        List<SysRadioVO> list = radioService.qryRadioRandList(query);

        return Result.ok(list);
    }

    @PostMapping("qryQuestionList")
    @Operation(summary = "获取题库列表")
    public Result<PageResult<SysRadioVO>> qryQuestionList(@RequestBody @Valid SysRadioQuery query){
        PageResult<SysRadioVO> page = radioService.qryQuestionList(query);
        return Result.ok(page);
    }
    @PutMapping
    @Operation(summary = "修改")
    public Result<String> updateRadio(@RequestBody @Valid SysRadioVO vo){
        radioService.updateRadio(vo);

        return Result.ok();
    }

    @PostMapping("save")
    @Operation(summary = "保存")
    public Result<String> save(@RequestBody SysRadioVO vo){
        radioService.addRadio(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    public Result<String> delete(@RequestBody List<Long> idList){
        radioService.delete(idList);
        return Result.ok();
    }
}

